package com.elai.operate.controller;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.domain.model.LoginUser;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.SecurityUtils;
import com.elai.operate.domain.OperatePalnDO;
import com.elai.operate.domain.OperatePlanGroupDO;
import com.elai.operate.service.OperatePlanGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/operate/planGroup")
public class OperatePlanGroupController extends BaseController {

    @Autowired
    private OperatePlanGroupService operatePlanGroupService;

    /**
     * 查询用户所属分组
     */
    @GetMapping("/getPlanGroupByUserId")
    public AjaxResult getPlanGroupByUserId(){
        LoginUser user= SecurityUtils.getLoginUser();
        Long userId = user.getUser().getUserId();
        List<OperatePlanGroupDO> operatePlanGroupDOList = operatePlanGroupService.getPlanGroupByUserId(userId);
        return AjaxResult.success(operatePlanGroupDOList);
    }

    /**
     * 新增计划分组
     */
    @PostMapping("/insertOperatePlanGroup")
    public AjaxResult insertOperatePlanGroup(@RequestBody OperatePlanGroupDO operatePlanGroupDO){
        return toAjax(operatePlanGroupService.insertOperatePlanGroup(operatePlanGroupDO));
    }

    /**
     * 修改计划分组
     */
    @Log(title = "运营计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperatePlanGroupDO operatePlanGroup)
    {
        operatePlanGroup.setUpdateTime(new Date());
        return toAjax(operatePlanGroupService.updateOperatePlanGroup(operatePlanGroup));
    }

    /**
     * 批量删除计划分组
     */
    /**
     * 删除运营计划
     */
    @Log(title = "运营计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operatePlanGroupService.deleteOperatePlanGroupByIds(ids));
    }

}
